package com.ybu.practice;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetPerson {
    public static void main(String[] args) {
        //1.创建TreeSet集合
        //2.Scanner对象 监听键盘录入数据
        //3.开启for 循环
        //4.在每个循环中，提示用户依次录入数据，创建Person对象，并把数据封装到Person对象中，将Person对象添加到TreeSet集合中
        //5.遍历TreeSet集合，输出数据
        TreeSet<Person> ts = new TreeSet<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                //o2的总成绩-01的总成绩
                return (int) (o2.getChinese() + o2.getMath() + o2.getEnglish() - o1.getChinese() - o1.getMath() - o1.getEnglish());
            }
        });
        Scanner scanner = new Scanner(System.in);


        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生姓名：");
            System.out.println(("请输入姓名："));
            String name = scanner.next();
            System.out.println("请输入第" + (i + 1) + "个学生语文成绩：");
            double chinese = scanner.nextDouble();
            System.out.println("请输入第" + (i + 1) + "个学生数学成绩：");
            double math = scanner.nextDouble();
            System.out.println("请输入第" + (i + 1) + "个学生英语成绩：");
            double english = scanner.nextDouble();
            //创建Person对象
            Person p = new Person(name, chinese, math, english);
            //将Person对象添加到TreeSet集合中
            ts.add(p);
        }
        for (Person p : ts) {
            System.out.println(p);
        }
    }
}
